<template>
    <view @tap="__e" :class="['coupon-item', 'margin-v', active ? 'active' : 'unactive']" :data-event-opts="[['tap', [['click', ['$event']]]]]">
        <view class="money-fl">
            <view class="price" v-if="baseCoupon.discount_type === 0">
                <text class="unit">¥</text>
                <text class="money">{{ baseCoupon.discount_money / 100 }}</text>
            </view>
            <block v-else>
                <view class="price" v-if="baseCoupon.discount_type === 1">
                    <text>{{ baseCoupon.discount_rate / 10 }}</text>
                    <text class="unit">折</text>
                </view>
                <block v-else>
                    <view class="price" style="font-size: 38rpx" v-if="baseCoupon.discount_type === 2">
                        <text>包邮</text>
                    </view>
                    <block v-else>
                        <view class="price" style="font-size: 36rpx" v-if="baseCoupon.discount_type === 3">
                            <text>兑换券</text>
                        </view>
                    </block>
                </block>
            </block>
            <view class="type">
                <text v-if="baseCoupon.discount_type === 0">优惠券</text>
                <block v-else>
                    <text v-if="baseCoupon.discount_type === 1">折扣券</text>
                    <block v-else>
                        <text v-if="baseCoupon.discount_type === 2">运费券</text>
                        <block v-else>
                            <text v-if="baseCoupon.discount_type === 3">兑换券</text>
                        </block>
                    </block>
                </block>
            </view>
        </view>
        <view class="detail">
            <view class="title">
                <text>{{ baseCoupon.title }}</text>
            </view>
            <view class="label" v-if="baseCoupon.score_price">
                <text v-if="baseCoupon.score_price">{{ baseCoupon.score_price + scoreAlias + '兑换' }}</text>
            </view>
            <view class="valid-date">
                <text class="labels">{{ baseCoupon.usable_range_text }}</text>
                <text>{{ validDateStr }}</text>
            </view>
            <view class="limit-type gray">
                <view v-if="baseCoupon.discount_type === 0">
                    <text v-if="baseCoupon.minimum_money">{{ '满' + baseCoupon.minimum_money / 100 + '元可用' }}</text>
                    <text v-else>{{ '使用立减' + baseCoupon.discount_money / 100 + '元' }}</text>
                </view>
                <block v-else>
                    <view v-if="baseCoupon.discount_type === 1">
                        <text v-if="baseCoupon.minimum_money">{{ '满' + baseCoupon.minimum_money / 100 + '元' }}</text>
                        <text>{{ '享' + baseCoupon.discount_rate / 10 + '折优惠' }}</text>
                    </view>
                    <block v-else>
                        <view v-if="baseCoupon.discount_type === 2">
                            <text v-if="baseCoupon.minimum_money">{{ '满' + baseCoupon.minimum_money / 100 + '元' }}</text>
                            <text>享受包邮优惠</text>
                        </view>
                        <block v-else>
                            <view v-if="baseCoupon.discount_type === 3">
                                <text>免费兑换指定的</text>
                                <text v-if="baseCoupon.usable_range_type === 1">盲盒</text>
                                <block v-else>
                                    <text v-if="baseCoupon.usable_range_type === 2">商品</text>
                                    <block v-else>
                                        <text v-if="baseCoupon.usable_range_type === 3">VIP套餐</text>
                                    </block>
                                </block>
                            </view>
                        </block>
                    </block>
                </block>
            </view>
        </view>
        <view class="discount-money">
            <view class="action">
                <view @tap="__e" class="btn" :data-event-opts="[['tap', [['toUse', ['$event']]]]]" v-if="active">{{ '' + activeText + '' }}</view>
                <view class="btnText" v-else>{{ '' + unActiveText + '' }}</view>
            </view>
        </view>
    </view>
</template>

<script>
import tabBar from '@/components/TabBar/tabBar';
(global.webpackJsonp = global.webpackJsonp || []).push([
    ['pages/myCoupons/components/CouponItem'],
    {
        '0e4c': function (t, e, n) {
            'use strict';

            var o = n('e6ca');
            n.n(o).a;
        },
        '24f7': function (t, e, n) {
            'use strict';

            (function (t) {
                var o = n('4ea4');
                Object.defineProperty(e, '__esModule', {
                    value: true
                });
                e.default = void 0;
                var u = o(n('8fc9'));
                var a = {
                    name: 'CouponItem',
                    props: {
                        coupon: {
                            type: Object,
                            default: function () {
                                return {};
                            }
                        },
                        active: {
                            type: Number,
                            default: 1
                        },
                        activeText: {
                            type: String,
                            default: '立即使用'
                        },
                        unActiveText: {
                            type: String,
                            default: '已使用'
                        }
                    },
                    computed: {
                        validDateStr: function () {
                            var t = this.coupon.usable_start_at;
                            var e = this.coupon.usable_end_at;
                            if (!e) {
                                return '';
                            }
                            var n = (0, u.default)(t);
                            var o = (0, u.default)(e);
                            var a = new Date();
                            if (n > a || o < a) {
                                return n.format('YYYY.MM.DD') + ' - ' + o.format('MM.DD');
                            }
                            var c = o.diff(a, 'days');
                            return c < 1 ? o.diff(a, 'h') + 1 + '小时后过期' : c + 1 + '天后过期';
                        },
                        scoreAlias: function () {
                            return this.$store.getters.scoreAlias;
                        },
                        baseCoupon: function () {
                            return this.coupon.base_coupon || {};
                        }
                    },
                    methods: {
                        toUse: function () {
                            this.baseCoupon.to_use_link && 'none' != this.baseCoupon.to_use_link.type
                                ? this.toLink(this.baseCoupon.to_use_link)
                                : t.switchTab({
                                      url: '/pages/index/index'
                                  });
                        },
                        goShop: function () {
                            t.switchTab({
                                url: '/pages/shop/index'
                            });
                        },
                        click: function () {
                            this.$emit('click', this.coupon);
                        }
                    }
                };
                e.default = a;
            }.call(this, n('543d').default));
        },
        '6d5c': function (t, e, n) {
            'use strict';

            n.d(e, 'b', function () {
                return o;
            });
            n.d(e, 'c', function () {
                return u;
            });
            n.d(e, 'a', function () {});
            var o = function () {
                this.$createElement;
                this._self._c;
            };
            var u = [];
        },
        '8db6': function (t, e, n) {
            'use strict';

            n.r(e);
            var o = n('6d5c');
            var u = n('ea5e');
            for (var a in u) {
                if (['default'].indexOf(a) < 0) {
                    (function (t) {
                        n.d(e, t, function () {
                            return u[t];
                        });
                    })(a);
                }
            }
            n('0e4c');
            var c = n('f0c5');
            var i = Object(c.a)(u.default, o.b, o.c, false, null, null, null, false, o.a, void 0);
            e.default = i.exports;
        },
        e6ca: function (t, e, n) {},
        ea5e: function (t, e, n) {
            'use strict';

            n.r(e);
            var o = n('24f7');
            var u = n.n(o);
            for (var a in o) {
                if (['default'].indexOf(a) < 0) {
                    (function (t) {
                        n.d(e, t, function () {
                            return o[t];
                        });
                    })(a);
                }
            }
            e.default = u.a;
        }
    }
]);
(global.webpackJsonp = global.webpackJsonp || []).push([
    'pages/myCoupons/components/CouponItem-create-component',
    {
        'pages/myCoupons/components/CouponItem-create-component': function (t, e, n) {
            n('543d').createComponent(n('8db6'));
        }
    },
    [['pages/myCoupons/components/CouponItem-create-component']]
]);
</script>
<style>
@import './CouponItem.css';
</style>
